var app = {
	description : 'App Common JS Library',
	version : '0.0.1'
};

app.login = {
	doLogin : function($form, callback) {
		var userName = $form.find('input[name=userName]').val();
		var password = $form.find('input[name=password]').val();
		$.ajax({
			type: "POST",
			url: webroot + "/system/userLogin",
			data: {
				userName:userName,
    	 		password:password
    	 	},
     		dataType: "json",
     		success: function(resp){
				if(resp.success){
					if (resp.content && resp.content.redirect) {
						location.href = webroot + resp.content.redirect;
					}
				} else {
					alert(resp.message);
				}
        	}
         });
	}
}


//格式化日期：年-月-日
app.inputDate = {
	myformatter : function(date) {
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		var d = date.getDate();
		return y + '-' + (m < 10 ? ('0' + m) : m) + '-'
				+ (d < 10 ? ('0' + d) : d);
	},

	myparser : function(s) {
		if (!s)
			return new Date();
		var ss = (s.split('-'));
		var y = parseInt(ss[0], 10);
		var m = parseInt(ss[1], 10);
		var d = parseInt(ss[2], 10);
		if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
			return new Date(y, m - 1, d);
		} else {
			return new Date();
		}
	},
	myformatterTime : function(date) {
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		var d = date.getDate();
		var h = date.getHours();
		var i = date.getMinutes();
		var s = date.getSeconds();
		return y + '-' + (m < 10 ? ('0' + m) : m) + '-'
				+ (d < 10 ? ('0' + d) : d) + ' ' + (h < 10 ? ('0' + h) : h)
				+ ':' + (i < 10 ? '0' + i : i) + ':' + (s < 10 ? '0' + s : s);
	}
};